﻿@model PcaPagos.BOL.oVwRegistro 

@{
    var X = Html.X();
}

@(
 X.GridPanel()
        .ID("GridRegistros")
        .Title("Pagos registrados")
        .Flex(1)
        .Store(
            X.StoreForModel()
                .ID("storeRegistros")
                .Buffered(true)
                .PageSize(100)
                .LeadingBufferZone(300)
                .Parameters(p =>
                {
                    p.Add(new StoreParameter() { Name = "filtroId", Value = "App.filtroId.getValue()", Mode = ParameterMode.Raw });
                    p.Add(new StoreParameter() { Name = "filtro", Value = "App.filtro.getValue()", Mode = ParameterMode.Raw });
                })
                .Proxy(
                    X.AjaxProxy()
                        .Url(Url.Action("GetList", "Registro"))
                        .Reader(X.JsonReader().RootProperty("data"))
                )
                .RemoteSort(false)
        )
        .DirectEvents(de =>
        {
            de.ItemDblClick.Url = Url.Action("RunCommandGrid", "Registro");
            de.ItemDblClick.ExtraParams.Add(new Parameter { Name = "commandName", Value = "cmdEditar", Mode = ParameterMode.Value });
            de.ItemDblClick.ExtraParams.Add(new Parameter { Name = "registroId", Value = "record.data.registro_id", Mode = ParameterMode.Raw });
            de.ItemDblClick.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
            de.ItemDblClick.Complete = "Ext.getBody().unmask();";
            de.ItemDblClick.Failure = "PcaGlobal.showError(result.msg);";
        })
        .ColumnModel(
                X.Column().DataIndex(Model, m => m.tipo_movimiento_id).Text("Tipo").Width(70).Align(Alignment.Center),
                X.Column().DataIndex(Model, m => m.codigo_grupo_movimiento).Text("Grupo").Flex(1),
                X.Column().DataIndex(Model, m => m.codigo_subgrupo_movimiento).Text("Sub Grupo").Flex(1),
                X.DateColumn().DataIndex(Model, m => m.fecha_emision).Text("Emision").Format("dd-MM-yyyy").Align(Alignment.Center).Width(120),
                X.DateColumn().DataIndex(Model, m => m.fecha_vencimiento).Text("Vencimiento").Format("dd-MM-yyyy").Align(Alignment.Center).Width(120),
                X.Column().DataIndex(Model, m => m.detalle).Text("Detalle").Flex(2),
                X.Column().DataIndex(Model, m => m.monto).Text("Monto").Flex(1).Align(Alignment.Right).Renderer("PcaGlobal.moneyFormat"),
                X.CheckColumn().DataIndex(Model, m => m.cancelado).Text("Pagado").Width(70),
                X.DateColumn().DataIndex(Model, m => m.fecha_hora_cancelacion).Text("Fecha Pago").Format("dd-MM-yyyy").Align(Alignment.Center).Width(120),
                X.CommandColumn().Hideable(false).Text("Operaciones").Align(Alignment.Center)
                    .Commands(
                        X.GridCommand().CommandName("cmdEditar").ToolTip(t => t.Text = "Editar movimiento").Icon(Icon.ApplicationEdit),
                        X.GridCommand().CommandName("cmdEliminar").ToolTip(t => t.Text = "Eliminar movimiento").Icon(Icon.ApplicationDelete),
                        X.GridCommand().CommandName("cmdPagar").ToolTip(t => t.Text = "Pagar registro").Icon(Icon.Money),
                        X.GridCommand().CommandName("cancelarPago").ToolTip(t => t.Text ="CancelarPago").Icon(Icon.MoneyDelete)     
                    )
                    .DirectEvents(de =>
                    {
                        de.Command.Url = Url.Action("RunCommandGrid", "Registro");
                        de.Command.ExtraParams.Add(new Parameter { Name = "commandName", Value = "command", Mode = ParameterMode.Raw });
                        de.Command.ExtraParams.Add(new Parameter { Name = "registroId", Value = "record.data.registro_id", Mode = ParameterMode.Raw });
                        de.Command.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                        de.Command.Complete = "Ext.getBody().unmask();";
                        de.Command.Failure = "PcaGlobal.showError(result.msg);";
                    })
        )
        .TopBar(
            X.Toolbar()
                .Items(
                    X.Button()
                        .ID("btnNuevo")
                        .Text("Nuevo")
                        .Icon(Icon.Add)
                        .DirectEvents(de =>
                        {
                            de.Click.Url = Url.Action("FrmRegistrar", "Registro");
                            de.Click.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                            de.Click.Complete = "Ext.getBody().unmask();";
                        }),
                        X.ToolbarSeparator(),
                        X.ComboBox()
                            .ID("filtroId")
                            .FieldLabel("Mostar")
                            .MarginSpec("0 7 0 7")
                            .LabelWidth(60)
                            .Width(250)
                            .QueryMode(DataLoadMode.Local)
                            .Editable(false)
                            .ForceSelection(true)
                            .DisplayField("nombre")
                            .ValueField("id")
                            .Value(0)//Por defecto mostrar todos
                            .Store(
                                X.StoreFor(typeof(PcaCore.DAL.oCampo))
                                    .AutoLoad(true)
                                    .Proxy(
                                        X.AjaxProxy()
                                            .Url(Url.Action("GetListFiltros"))
                                            .Reader(X.JsonReader().RootProperty("data"))
                                    )
                            )
                            .Listeners(l =>
                            {
                                l.Select.Handler = @"App.GridRegistros.getSelectionModel().deselectAll();
                                                     App.storeRegistros.load();";
                            }),
                        X.ToolbarSeparator(),
                        X.Checkbox()
                            .ID("chkDisabledAlertas")
                            .FieldLabel("Alertas activadas")
                            .LabelWidth(120) 
                            .Checked(true) 
                            .Listeners(ls =>
                            {
                                ls.Change.Handler = @"if(!newValue){
                                                        App.TaskManager1.stopTask('TaskAlertas');
                                                      }else{
                                                        App.TaskManager1.startTask('TaskAlertas');
                                                      }";
                            }),
                        X.ToolbarFill(),
                        X.TextField()
                            .ID("filtro")
                            .Width(150)
                            .EnableKeyEvents(true)
                            .EmptyText("Filtro...")
                            .Triggers(
                                X.FieldTrigger()
                                    .Hidden(true)
                                    .Icon(TriggerIcon.Clear)
                            )
                            .Listeners(l =>
                            {
                                l.KeyUp.Handler = @"if (Ext.isEmpty(App.filtro.getValue(), false)) {
                                                        App.filtro.setValue('');
                                                        App.filtro.getTrigger(0).hide();
                                                    } else {
                                                        App.filtro.getTrigger(0).show();
                                                    }";

                                l.TriggerClick.Handler = @"App.filtro.setValue('');
                                                           App.filtro.getTrigger(0).hide();
                                                           App.GridRegistros.getSelectionModel().deselectAll();
                                                           App.storeRegistros.load();";

                                l.SpecialKey.Handler = @"if(e.getKey() == e.ENTER){
                                                            e.stopEvent();
                                                            App.GridRegistros.getSelectionModel().deselectAll();
                                                            App.storeRegistros.load();
                                                        }";
                            }),
                         X.Button()
                            .ID("btnActualizarGrid")
                            .Text("Actualizar")
                            .Icon(Icon.ArrowRotateAnticlockwise)
                            .Handler("App.GridRegistros.getSelectionModel().deselectAll(); App.storeRegistros.load();")
                )
       )
)
